/**
 * 封装本地存储(只支持ie8及以上现代浏览器)
 * @module storage
 * @author pmkx2 (185832959@qq.com)
 */
define('storage', [], function(){
    var Storage = function(){
        this.localStorage = window.localStorage;
        this.prefixName   = '_storage';
    };

    /**
     * 设置值
     *
     * @param {String} key - 存储的索引key
     * @param {Mixed} val - 存储的值:String, Array, Object[基础类型]
     * @return {Void}
     */
    Storage.prototype.set = function(key, val){
        var self = this;
        if(null === val || undefined === val){
            return;
        }
        self.localStorage.setItem(self.prefixName + key, JSON.stringify(val));
    };

    /**
     * 取值
     *
     * @param {String} key - 存储的索引key
     * @param {Mixed} def - 当没有数据时，返回的默认值，默认为: null
     * @return {Mixed}
     */
    Storage.prototype.get = function(key, def){
        var self = this;
        var val = self.localStorage.getItem(self.prefixName + key);
        def = def === undefined ? null : def;
        return null === val ? def : JSON.parse(val);
    };

    /**
     * 删除值
     *
     * @param {String} key - 存储的索引key
     */
    Storage.prototype.remove = function(key){
        var self = this;
        return self.localStorage.removeItem(self.prefixName + key);
    };

    return Storage;
});